package cn.dsscm.controller;

import cn.dsscm.pojo.User;
import cn.dsscm.service.UserService;
import com.alibaba.fastjson.JSONArray;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> login(@RequestBody User user){
        User list=userService.login(user);
         Map<String,Object> map = new HashMap<>();
         if (list == null){
             map.put("msg","失败"); 
         }else {
             map.put("msg","成功");
             map.put("success",true);
             map.put("data",list);
         }
         return map;
    }

    @RequestMapping(value = "/register",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> register(@RequestBody User user){
        Integer register = userService.register(user);
        Map<String,Object> map1 = new HashMap<>();
        if (register<0){
            map1.put("msg","失败");
            map1.put("success",false);
        }else {
            map1.put("msg","成功");
            map1.put("success",true);
        }
        return map1;
    }
}
